extends Area2D

const Fish = preload("res://scenes/fish/fish.tscn")
const DiseasedFish = preload("res://scenes/fish/diseased_fish/diseased_fish.tscn")

@onready var fishes = $Fishes

var is_initing = false
var radius : int = 200
var center : Vector2 = Vector2(576,324)

var normal_fish_count : int = 0

func clear_fishes() -> void:
	normal_fish_count = 0
	for fish in fishes.get_children():
		fish.queue_free()

func contains_normal_fish() -> bool:
	if normal_fish_count == 0:
		return false
	else:
		return true

func spawn_fishes(fishes_count: Vector2) -> void:
	normal_fish_count = fishes_count.x
	for i in fishes_count.x: #normal
		spawn_fish(true)
	for i in fishes_count.y: #diseased
		spawn_fish(false)
	is_initing = false

func spawn_fish(normal : bool) -> void:
	var fish
	if normal:
		fish = Fish.instantiate()
	else:
		fish = DiseasedFish.instantiate()
	fish.area_entered.connect(randomise_position)
	randomise_position(fish)
	fishes.add_child(fish)

func randomise_position(fish: Node2D) -> void:
	var x = randi_range(center.x - radius, center.x + radius)
	var y = randi_range(center.y - radius, center.y + radius)
	fish.position = Vector2(x, y)

#Globals.fish_collecte
#print(contains_normal_fishes())
